<template>
    <div class="panel-title">
        用户登录
    </div>
    <div class="panel-body">
        <table style="text-align: center ;">
            <tr>
                <td>用户名</td>
                <td><input type="text" v-model="uname" /></td>
            </tr>
            <tr>
                <td>密码</td>
                <td><input type="password" v-model="upwd" /></td>
            </tr>
            <tr>
                <td colspan="2"> <input type="button" value="提交" @click="Login()"> </td>
            </tr>
        </table>
    </div>
</template>
<!---->
<script lang="ts" setup>
import { ref } from 'vue';
import axios from 'axios';
//import { useRouter } from 'vue-router';
let uname = ref("");
let upwd = ref("");
var uid=ref("");
//let router =  useRouter();
function Login() {
    if (uname.value == "" || upwd.value == "") {
        alert("用户名 密码不能为空");
        return;
    }
    axios.post("https://localhost:44395/ULogin?uname=" + uname.value + "&upwd=" + upwd.value)
        .then(function (res) {
            console.log(res.data);
            if (res.data == null || res.data.length == 0) {
                alert('用户名密码错误');
                return;
            }
            else {
                alert('登录成功');
                //localStorage.setItem("token", res.data.uid);
                uid.value=res.data.U_Id;
                handleEmit();
                
                //router.push({name:'userrole',params:{uid:res.data.U_Id,uname:res.data.UL_Name}})
            }
        })
        .catch(function (err) {
            console.log(err);
        });
}

const msgs = defineEmits(["valname"]);


const handleEmit = () => {
    msgs('valname', uid.value) //value是传给父元素事件的参数
}


</script>